/**
 * CS202 - Spring 2009 
 * Professor: Dr. Michael Peterson
 * Student: Deylo Woo (dwoo711@gmail.com)
 */
package lab5;

import java.awt.*;

/**
 * Ball class
 */
public class Ball {

    //declare all internal variables for this class
    private int _xCoord;
    private int _yCoord;
    private int _height;
    private int _width;
    private int _rise;
    private int _run;
    private Color _color;

    /**
     * Ball Constructor, takes no parameter, it randomizes everything
     */
    public Ball() {
        //Randomly set balls prefs
        _xCoord = (int) (Math.random() * 50);
        _yCoord = (int) (Math.random() * 50);
        _height = _width = (int) ((Math.random() * 20) + 10); //range from 10-20
        // _width = (int) ((Math.random() * 20) + 10); //range from 10-20
        _rise = (int) (Math.random() * 10);
        _run = (int) (Math.random() * 10);
        _color = GetRandomColor();
    }

    /**
     * Ball Constructor, takes setting parameters
     * @param xCoord: x position in panel
     * @param yCoord: y positoin in panel
     * @param height: obj height
     * @param width: obj width
     * @param rise: velocity rise
     * @param run: velocity run
     */
    public Ball(int xCoord, int yCoord, int height, int width, int rise, int run,
            int pPanelHeight, int pPanelWidth) {
        _xCoord = xCoord;
        _yCoord = yCoord;
        _height = height;
        _width = width;
        _rise = rise;
        _run = run;
    }

    //Public Access and Public Mofifiers
    public int getXCoord() {
        return _xCoord;
    }

    public void setXCoord(int xCoord) {
        this._xCoord = xCoord;
    }

    public int getYCoord() {
        return _yCoord;
    }

    public void setYCoord(int yCoord) {
        this._yCoord = yCoord;
    }

    public int getHeight() {
        return _height;
    }

    public void setHeight(int height) {
        this._height = height;
    }

    public int getWidth() {
        return _width;
    }

    public void setWidth(int width) {
        this._width = width;
    }

    public int getRise() {
        return _rise;
    }

    public void setRise(int rise) {
        this._rise = rise;
    }

    public int getRun() {
        return _run;
    }

    public void setRun(int run) {
        this._run = run;
    }

    public Color getColor() {
        return _color;
    }

    public void setColor(Color color) {
        this._color = color;
    }
    //****************  Methods
    /**
     * Generate randorm color
     * @return: Color as Color object
     */
    private Color GetRandomColor() {
        int red = (int) (Math.random() * 255);
        int green = (int) (Math.random() * 255);
        int blue = (int) (Math.random() * 255);
        return new Color(red, green, blue);
    }

    /**
     * Move Ball in relation to Panel Height and width
     * @param pPanelHeight: panel height
     * @param pPanelWidth: panel width
     */
    public void Move(int pPanelHeight, int pPanelWidth) {

        if (_xCoord < (0 - _run) || _xCoord > (pPanelWidth - _width)) {
            _run = -_run;
        }

        if (_yCoord < (0 - _rise) || _yCoord > (pPanelHeight - _height)) {
            _rise = -_rise;
        }

        _xCoord += _run;
        _yCoord += _rise;
    }

    /**
     * Paint the object
     * @param g: Graphics to be painted on Panel
     */
    public void paint(Graphics g) {
        g.setColor(_color);
        g.fillOval(_xCoord, _yCoord, _width, _height);
    }
}

